package com.bawei.nscreendemo;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.ImageUtils;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class MainActivity extends AppCompatActivity {
    private ImageView iv;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = findViewById(R.id.iv);
        requestPermissions(new String[]{
                "android.permission.WRITE_EXTERNAL_STORAGE",
                "android.permission.READ_EXTERNAL_STORAGE"
        },101);

    }

    public void jietu(View view) {
        View decorView = getWindow().getDecorView();
        decorView.setDrawingCacheEnabled(true);//设置可以缓存
        decorView.buildDrawingCache();//缓存一下，截图
        Bitmap bitmap = decorView.getDrawingCache();//得到截图
        Bitmap bitmap1 = ImageUtils.addTextWatermark(bitmap, "八维", 100, Color.BLACK, bitmap.getWidth() / 2 - 100, bitmap.getHeight() / 2 - 100);

        iv.setImageBitmap(bitmap1);




//        //将图片缓存到SD卡中
//        try {
//            //参数一 格式  参数二 质量  参数三 SD卡输出流
//            String createname = "jietu.jpg";
//            bitmap.compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream("/sdcard/DCIM/Camera/"+createname));
//
//
//
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }



    }
}